# 描述: 启动程序
# 作者: 王茂林
# 时间: 2024/2/22 16:39

import argparse
import RunrisetCollector as runrisetCollector
import common.logger as logger

if __name__ == '__main__':
    """
    生成requirements.txt命令:
    pip freeze > requirements.txt
    
    cd进项目根目录，执行以下命令安装依赖:
    pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com -r requirements.txt
    
    启动命令:
    UAT内网测试(bat)：
    title video-linkage
    cd D:\PycharmProjects\iori-runriset
    D:
    python app.py -n=runriset -ll=debug -host=10.1.200.199 -port=32695 -longitude=114.079859 -latitude=22.712489
    -ci=GrbaGrZXCeQ_sunriset-longhua_0_0_1711436408955 -un=GrbaGrZXCeQ_sunriset-longhua -pwd=3F2D3022AB235A5A6FE48BDE0D0B104F927ECA2A129F746B067C04901630DCEC

    百度地图的坐标拾取器(经度,纬度)： http://api.map.baidu.com/lbsapi/getpoint/index.html
     """

    parser = argparse.ArgumentParser(description='argparse testing')
    parser.add_argument('--app_name', '-n', type=str, default="iori-runriset", required=False,
                        help="应用名称，多实例运行时要保证唯一性")
    # MQTT相关参数
    parser.add_argument('--client_id', '-ci', type=str, default=None, required=False, help="MQTT客户端ID")
    parser.add_argument('--username', '-un', type=str, default=None, required=False, help="MQTT用户名")
    parser.add_argument('--pwd', '-pwd', type=str, default=None, required=False, help="MQTT密码")
    parser.add_argument('--host', '-host', type=str, default="prod.rlinkiot.com", required=False,
                        help="MQTT主机地址,不需要协议")
    parser.add_argument('--port', '-port', type=int, default=4435, required=False, help="MQTT主机端口号")
    parser.add_argument('--log_level', '-ll', type=str, default="debug", required=False, help="日志级别")
    # 经度,纬度.默认锦绣科学园
    parser.add_argument('--longitude', '-longitude', type=float, default=114.079859, required=False, help="经度")
    parser.add_argument('--latitude', '-latitude', type=float, default=22.712489, required=False, help="纬度")

    args = parser.parse_args()

    # 初始化日志配置
    logger.init_logger(logger.args_to_log_level(args.log_level), f'{args.app_name}.log')

    logger.info('-------------------------------------------------')
    logger.info('   欢迎使用IORI runriset-collector，采集日出日落时间，大林祝您梦想成真！！！')
    logger.info('-------------------------------------------------')

    logger.debug(f'args.log_level: {args.log_level}')
    logger.debug(f'args.app_name: {args.app_name}')

    logger.debug(f'MQTT.client_id: {args.client_id}')
    logger.debug(f'MQTT.username: {args.username}')
    logger.debug(f'MQTT.pwd: {args.pwd}')
    logger.debug(f'MQTT.host: {args.host}')
    logger.debug(f'MQTT.port: {args.port}')

    logger.debug(f'Location.longitude: {args.longitude}')
    logger.debug(f'Location.latitude: {args.latitude}')

    # 扩展参数
    kwargs = {
        # MQTT连接参数
        "client_id": args.client_id,
        "username": args.username,
        "pwd": args.pwd,
        "host": args.host,
        "port": args.port,
        # 经纬度参数
        "longitude": args.longitude,
        "latitude": args.latitude
    }
    runner = runrisetCollector.RunrisetCollector(app_name=args.app_name, **kwargs)
    runner()

